package Data_base;
import java.sql.*;
import java.util.*;//获取Scanner
//登陆
public class Denglu {
          public void login() throws Exception {
              try {
                  DB ty = new DB();
                  Class.forName(ty.Driver_class);
                  Connection conn = DriverManager.getConnection(ty.Database_url, ty.Database_user, ty.Database_password);
                  Scanner sc = new Scanner(System.in);
                  System.out.print("请输入登陆id:");
                  String zh = sc.nextLine();
                  System.out.print("请输入密码:");
                  String mm = sc.nextLine();
                  //到数据库验证用户名和密码是否正确
                  Statement state = conn.createStatement();
                  String sql = "select * from users where id='" + zh + "' and password='" + mm + "'";
                  ResultSet re = state.executeQuery(sql);
                  if (re.next()) {
                      System.out.println("登陆成功！" + re.getString(2) + " 欢迎你");
                  } else {
                      System.out.println("输入账号或密码错误");
                  }
                  conn.close();
              }catch(Exception e)
              {
                  e.printStackTrace();
              }
           }
}
